*/
+#include "tpg.h"
+
#include <cctype> // for isalnum
#include <cstring> // for memcmp
#include <QChar> // for QChar
#include <QString> // for QString
-#include <QVector> // for QVector
#include "defs.h"
-#include "gbfile.h" // for gbfwrite, gbfgetint16, gbfputint16, gbfclose
-#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Known_Da...
+#include "gbfile.h" // for gbfwrite, gbfgetint16, gbfputint16, gbfclose, gbfgetdbl, gbfgetpstr, gbfopen_le, gbfputdbl, gbfgetint32, gbfputc, gbfputpstr, gbfread
+#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M, GPS_Math_WGS84_To_Known_Datum_M
#include "mkshort.h" // for MakeShort
#define MAXTPGSTRINGSIZE 256
#define MAXTPGOUTPUTPINS 65535
-static gbfile* tpg_file_in;
-static gbfile* tpg_file_out;
-static MakeShort* mkshort_handle;
-static char* tpg_datum_opt;
-static int tpg_datum_idx;
-
-static unsigned int waypt_out_count;
-
-static
-QVector<arglist_t> tpg_args = {
- {"datum", &tpg_datum_opt, "Datum (default=NAD27)", "N. America 1927 mean", ARGTYPE_STRING, ARG_NOMINMAX , nullptr},
-};
-
-static int
-valid_tpg_header(char* header, int len)
+int
+TpgFormat::valid_tpg_header(char* header, int len)
{
unsigned char header_bytes[] = { 0xFF, 0xFF, 0x01, 0x00, 0x0D,
0x00, 0x43, 0x54, 0x6F, 0x70,
return memcmp(header_bytes, header, len);
}
-static void
-tpg_common_init()
+void
+TpgFormat::tpg_common_init()
{
tpg_datum_idx = GPS_Lookup_Datum_Index(tpg_datum_opt);
if (tpg_datum_idx < 0) {
}
}
-static void
-tpg_rd_init(const QString& fname)
+void
+TpgFormat::rd_init(const QString& fname)
{
tpg_common_init();
tpg_file_in = gbfopen_le(fname, "rb", MYNAME);
}
-static void
-tpg_rd_deinit()
+void
+TpgFormat::rd_deinit()
{
gbfclose(tpg_file_in);
}
-static void
-tpg_wr_init(const QString& fname)
+void
+TpgFormat::wr_init(const QString& fname)
{
tpg_common_init();
tpg_file_out = gbfopen_le(fname, "wb", MYNAME);
waypt_out_count = 0;
}
-static void
-tpg_wr_deinit()
+void
+TpgFormat::wr_deinit()
{
delete mkshort_handle;
gbfclose(tpg_file_out);
}
-static void
-tpg_read()
+void
+TpgFormat::read()
{
char buff[MAXTPGSTRINGSIZE + 1];
double amt;
}
}
-static void
-tpg_waypt_pr(const Waypoint* wpt)
+void
+TpgFormat::tpg_waypt_pr(const Waypoint* wpt)
{
double lon, lat;
double amt;
}
}
-static void
-tpg_write()
+void
+TpgFormat::write()
{
unsigned char header_bytes[] = { 0xFF, 0xFF, 0x01, 0x00, 0x0D,
0x00, 0x43, 0x54, 0x6F, 0x70,
/* write the rest of the header */
gbfwrite(header_bytes, 1, 19, tpg_file_out);
- waypt_disp_all(tpg_waypt_pr);
+ auto tpg_waypt_pr_lambda = [this](const Waypoint* waypointp)->void {
+ tpg_waypt_pr(waypointp);
+ };
+ waypt_disp_all(tpg_waypt_pr_lambda);
}
-
-ff_vecs_t tpg_vecs = {
- ff_type_file,
- FF_CAP_RW_WPT,
- tpg_rd_init,
- tpg_wr_init,
- tpg_rd_deinit,
- tpg_wr_deinit,
- tpg_read,
- tpg_write,
- nullptr,
- &tpg_args,
- NULL_POS_OPS
-};
--- /dev/null
+/*
+ National Geographic Topo! TPG file support (Waypoints/Routes)
+ Contributed to gpsbabel by Alex Mottram
+
+ For Topo! version 2.x. Routes are currently not implemented.
+
+ Copyright (C) 2002 Alex Mottram, geo_alexm at cox-internet.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ */
+#ifndef TPG_H_INCLUDED_
+#define TPG_H_INCLUDED_
+
+#include <QString> // for QString
+#include <QVector> // for QVector
+
+#include "defs.h"
+#include "format.h" // for Format
+#include "gbfile.h" // for gbfile
+#include "mkshort.h" // for MakeShort
+
+
+class TpgFormat : public Format
+{
+public:
+ using Format::Format;
+
+ QVector<arglist_t>* get_args() override
+ {
+ return &tpg_args;
+ }
+
+ ff_type get_type() const override
+ {
+ return ff_type_file;
+ }
+
+ QVector<ff_cap> get_cap() const override
+ {
+ return FF_CAP_RW_WPT;
+ }
+
+ void rd_init(const QString& fname) override;
+ void read() override;
+ void rd_deinit() override;
+ void wr_init(const QString& fname) override;
+ void write() override;
+ void wr_deinit() override;
+
+private:
+ /* Member Functions */
+
+ static int valid_tpg_header(char* header, int len);
+ void tpg_common_init();
+ void tpg_waypt_pr(const Waypoint* wpt);
+
+ /* Data Members */
+
+ gbfile* tpg_file_in{};
+ gbfile* tpg_file_out{};
+ MakeShort* mkshort_handle{};
+ char* tpg_datum_opt{};
+ int tpg_datum_idx{};
+
+ unsigned int waypt_out_count{};
+
+ QVector<arglist_t> tpg_args = {
+ {"datum", &tpg_datum_opt, "Datum (default=NAD27)", "N. America 1927 mean", ARGTYPE_STRING, ARG_NOMINMAX, nullptr},
+ };
+};
+#endif // TPG_H_INCLUDED_
#include "src/core/logging.h" // for Warning, FatalMsg
#include "subrip.h" // for SubripFormat
#include "text.h" // for TextFormat
+#include "tpg.h" // for TpgFormat
#include "tpo.h" // for Tpo2Format, Tpo3Format
#include "unicsv.h" // for UnicsvFormat
#include "v900.h" // for V900Format
extern ff_vecs_t geo_vecs;
extern ff_vecs_t ozi_vecs;
#if MAXIMAL_ENABLED
-extern ff_vecs_t tpg_vecs;
extern ff_vecs_t gpl_vecs;
extern ff_vecs_t mtk_vecs;
extern ff_vecs_t mtk_fvecs;
KmlFormat kml_fmt;
#if MAXIMAL_ENABLED
LowranceusrFormat lowranceusr_fmt;
- LegacyFormat tpg_fmt {tpg_vecs};
Tpo2Format tpo2_fmt;
Tpo3Format tpo3_fmt;
#if SHAPELIB_ENABLED
nullptr,
},
{
- &tpg_fmt,
+ nullptr,
"tpg",
"National Geographic Topo .tpg (waypoints)",
"tpg",
nullptr,
+ &fmtfactory<TpgFormat>
},
{
&tpo2_fmt,